package org.bees.cms.core.io;

import java.io.File;

import org.bees.cms.common.Files;

public class Document extends IO {
	private static final long serialVersionUID = 7486712661578809313L;

	{
		flag = true;
	}

	private Directory directory;

	public Document() {
		super();
	}

	public Document(String path) throws Exception {
		super(path);
	}

	@Override
	public long size() throws Exception {
		return file.length();
	}

	@Override
	public void save() throws Exception {
		File temp = new File(Files.absolute(directory.getPath() + "/" + name));
		Files.copy(file, temp);
	}

	@Override
	public void omit() throws Exception {
		file.delete();
	}

	@Override
	public void name(String name) throws Exception {
		File temp = new File(Files.absolute(directory.getPath() + "/" + name));
		file.renameTo(temp);
		this.from(temp);
	}

	@Override
	public void move(String path) throws Exception {
		File temp = new File(Files.absolute(path + "/" + name));
		Files.copy(file, temp);
		file.delete();
	}

	@Override
	public void copy(String path) throws Exception {
		File temp = new File(Files.absolute(path + "/" + name));
		Files.copy(file, temp);
	}

	@Override
	public void hide() throws Exception {
		Runtime.getRuntime().exec("attrib " + file.getAbsolutePath() + " +H");
	}

	@Override
	public void show() throws Exception {
		Runtime.getRuntime().exec("attrib " + file.getAbsolutePath() + " -H");
	}

	public String type() throws Exception {

		return null;
	}

	@Override
	public void from(File t) throws Exception {
		super.from(t);
		directory = new Directory();
		directory.from(t.getParentFile());
	}

	@Override
	public File to() throws Exception {
		return super.to();
	}

	public Directory getDirectory() {
		return directory;
	}

	public void setDirectory(Directory directory) {
		this.directory = directory;
	}

}
